﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TARLib.Operazioni
{
    public class Operazione_Comanda : Operazione
    {
        // 100[NNNNNN]
        public Operazione_Comanda(string barcodeString)
            : base(barcodeString)
        {
            if (barcodeString.Length == 9)
            {
                if (barcodeString.Substring(0, 3) == "100")
                {
                    int comandaID;
                    if (!int.TryParse(barcodeString.Substring(3, 6), out comandaID))
                    {
                        throw new Exception("Barcode chars 4-9 (" + barcodeString.Substring(3, 6) + ") are invalid. Expected: int value");
                    }

                    ComandaID = comandaID;
                }
                else
                {
                    throw new Exception("Barcode first 3 chars (" + barcodeString.Substring(0, 3) + ") are invalid. Expected: 100");
                }
            }
            else
            {
                throw new Exception("Barcode lenght (" + barcodeString + ") is invalid. Expected: 9");
            }
        }

        public Operazione_Comanda(int comandaID)
        {
            ComandaID = comandaID;
        }

        public Operazione_Comanda()
            : base()
        {
        }

        public int ComandaID { get; set; }
        public override TipoOperazione Tipo { get { return TipoOperazione.Comanda; } }
        public override string BarcodeString { get { return String.Format("100{0}", ComandaID.ToString().PadLeft(6, '0')); } }
    }
}
